﻿using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            testcb.DataContext = this;

            // Initialize the collection with some sample data
            GrayMods.Add(new MouduleXSelectItem { Name = "Module 1", Description = "Description for Module 1", IsSelected = false, IconPath = "pack://application:,,,/Images/icon1.png" });
            GrayMods.Add(new MouduleXSelectItem { Name = "Module 2", Description = "Description for Module 2", IsSelected = false, IconPath = "pack://application:,,,/Images/icon2.png" });
            GrayMods.Add(new MouduleXSelectItem { Name = "Module 3", Description = "Description for Module 3", IsSelected = false, IconPath = "pack://application:,,,/Images/icon3.png" });
            GrayMods.Add(new MouduleXSelectItem { Name = "Module 4", Description = "Description for Module 4", IsSelected = false, IconPath = "pack://application:,,,/Images/icon4.png" });
            GrayMods.Add(new MouduleXSelectItem { Name = "Module 5", Description = "Description for Module 5", IsSelected = false, IconPath = "pack://application:,,,/Images/icon5.png" });


            // 注册全局 MouseEnter 事件
            EventManager.RegisterClassHandler(
                typeof(ComboBoxItem),
                UIElement.MouseEnterEvent,
                new MouseEventHandler(ComboBoxItem_MouseEnter));

            Lv.ItemsSource = GrayMods;
        }
        private ObservableCollection<MouduleXSelectItem> grayMods = new ObservableCollection<MouduleXSelectItem>();
        public ObservableCollection<MouduleXSelectItem> GrayMods
        {
            get { return grayMods; }
            set { grayMods = value; }
        }


        private void ComboBoxItem_MouseEnter(object sender, MouseEventArgs e)
        {
            if (sender is ComboBoxItem comboBoxItem)
            {
                // Get the data context of the ComboBoxItem
                var item = comboBoxItem.DataContext as MouduleXSelectItem;
                if (item != null)
                {
                    Console.WriteLine($"Mouse entered ComboBoxItem {item.Name}");
                }
            }
        }
        private void ComboBoxItem_MouseLeave(object sender, MouseEventArgs e)
        {
            if (sender is ComboBoxItem comboBoxItem)
            {
                // Get the data context of the ComboBoxItem
                var item = comboBoxItem.DataContext as MouduleXSelectItem;
                if (item != null)
                {
                    Console.WriteLine($"Mouse leave ComboBoxItem {item.Name}");
                }
            }
        }

        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            Console.WriteLine($"Mouse leave ComboBoxItem");
        }
    }
    public class MouduleXSelectItem
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public bool IsSelected { get; set; }
        public string IconPath { get; set; } // Path to the icon image
    }
}